package cn.e2win.biz.activity;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.e2win.base.controller.MyException;
import cn.e2win.base.entity.SysAttach;
import cn.e2win.base.entity.SysLabel;
import cn.e2win.base.json.vo.Pager;
import cn.e2win.biz.base.BaseDAO;
import cn.e2win.biz.base.BaseService;
import cn.e2win.biz.base.CommonService;
import cn.e2win.biz.dbo.Activity;
import cn.e2win.biz.dbo.DsRelation;
import cn.e2win.biz.dbo.GuestRelation;
import cn.e2win.biz.util.DateUtils;


@Service
public class ActivityService extends BaseService{

	@Autowired
	private ActivityDao activityDao;
	@Autowired
	private CommonService commonService;
	
	@Override
	public BaseDAO initDao() {
		return activityDao;
	}
	@Transactional
	public void pagerActivity(Pager pager){
		activityDao.pagerActivity(pager);
	}

	@Transactional
	public Activity editActivity(Activity obj, List<DsRelation> dsList, List<GuestRelation> guestList) throws MyException {
		//保存主图片

		if(obj.getMainPic()!=null && obj.getMainPic().getSize()>0){
			SysAttach attach = uploadFile(obj.getMainPic());
			obj.setMainPicUrl(attach.getFilePath());
		}
		Activity activity = (Activity)super.edit(obj);
		String clazz = activity.getClass().getSimpleName();

		//保存海报
		List<SysAttach> attachList=uploadFile(obj.getPosterFile() , new SysAttach(activity, "poster"));
		super.saveAll(attachList);

		//保存导师列表
		commonService.saveDsRelationList(activity, dsList);
		//保存导师列表
		commonService.saveGuestRelationList(activity, guestList);
		

		String activityTag = obj.getActivityTag();
		SysLabel labelTpl = new SysLabel();
		labelTpl.setEntityId(activity.getId());
		labelTpl.setLabelType("activityTag");
		labelTpl.setEntityType(clazz);
		commonService.editLabel(activityTag, labelTpl);

		return activity;
	}
	public  Map<String, Object> getActivityOrgDetail(Integer id, Map<String, String> param) {
		return activityDao.getCyzjOrgDetail(id, param);
	}

}

